package com.dangf.hzapp.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;

import com.dangf.hzapp.HzApplication;
import com.dangf.hzapp.widget.CustomProgressDialog;

/**
 * 基础 Activity
 * 
 * @author 韦海生
 * @date 2014年8月1日
 */
public abstract class BaseActivity extends Activity  {
	protected HzApplication app;
	protected CustomProgressDialog dialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		app = (HzApplication) getApplication();
		getActionBar().setTitle(getActivityName());		//设置标题
		getActionBar().setDisplayHomeAsUpEnabled(true);		//显示返回上级
		getActionBar().setDisplayShowHomeEnabled(false);	//显示图标
		
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}
	
	
	/**
	 * 用于获取 Activity名称
	 * @return
	 */
	protected abstract String getActivityName();
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			if(!"合租账簿".equals(getActivityName())){
				this.finish();
			}
			break;
		}
		return super.onOptionsItemSelected(item);
	}
	
	
	
	/**
	 * 显示进度条
	 */
	public void showDialog(){
		if (dialog == null){
			dialog = CustomProgressDialog.createDialog(this);
		}
		dialog.show();
	}
	
	/**
	 * 隐藏进度条
	 */
	public void hideDialog(){
		dialog.hide();
		dialog.setMessage("");
	}

	/**
	 * 显示titile
	 * @param msg
	 */
	public void showDialog(String msg){
		showDialog();
		if(dialog!=null)dialog.setMessage(msg);
	}
	
	
	

}
